home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_098 / thai / printer.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  102 lines

  1.  
  2. /*
  3.  * Printer interface functions
  4.  *
  5.  *
  6.  * extern LONG OpenPrinter ();
  7.  *        Returns TRUE if succeeds, FALSE if fails.
  8.  *
  9.  * extern void ClosePrinter ();
  10.  *        The printer must have been opened.
  11.  *
  12.  * extern LONG PrintString ( char * string );
  13.  *        Print the null terminated string on the printer.
  14.  *        Returns the status of DoIO()
  15.  *
  16.  * extern LONG DumpScreen ( struct Screen * screen );
  17.  *        Dumps an intuition screen on the printer in black and white.
  18.  *        Returns the status of DoIO()
  19.  *
  20.  */
  21.  
  22. #include <exec/types.h>
  23. #include <intuition/intuition.h>
  24. #include <devices/printer.h>
  25. #include "printer.h"
  26.  
  27.  
  28. extern struct MsgPort *        CreatePort ();
  29. extern struct IORequest *    CreateExtIO ();
  30. extern LONG                    OpenDevice ();
  31. extern LONG                    DoIO ();
  32.  
  33.  
  34. union printerIO {
  35.     struct IOStdReq            ios;
  36.     struct IODRPReq            iodrp;
  37.     struct IOPrtCmdReq        iopc;
  38. };
  39.  
  40.  
  41. static union printerIO *    prt_request;
  42. static struct MsgPort *        prt_port;
  43.  
  44.  
  45.  
  46. LONG
  47. OpenPrinter ()
  48. {
  49.     prt_port = CreatePort ( (char *)NULL , (LONG)0 );
  50.     if ( prt_port != NULL ) {
  51.         prt_request = (union printerIO *)
  52.             CreateExtIO ( prt_port , (LONG)sizeof ( union printerIO ) );
  53.         if ( prt_request != NULL ) {
  54.             if ( OpenDevice ( "printer.device" , (LONG)0 , prt_request , (LONG)0 ) == 0 ) {
  55.                 return ( TRUE );
  56.             }
  57.             DeleteExtIO ( prt_request , (LONG)sizeof ( union printerIO ) );
  58.         }
  59.         DeletePort ( prt_port );
  60.     }
  61.     return ( FALSE );
  62. }
  63.  
  64.  
  65. void
  66. ClosePrinter ()
  67. {
  68.     CloseDevice ( prt_request );
  69.     DeleteExtIO ( prt_request , (LONG) sizeof ( union printerIO ) );
  70.     DeletePort ( prt_port );
  71. }
  72.  
  73.  
  74. LONG
  75. PrintString ( str )
  76. char *str;
  77. {
  78.     prt_request->ios.io_Command = CMD_WRITE;
  79.     prt_request->ios.io_Length = -1;
  80.     prt_request->ios.io_Data = (APTR) str;
  81.     return ( DoIO ( prt_request ) );
  82. }
  83.  
  84.  
  85. LONG
  86. DumpScreen ( screen )
  87. struct Screen *screen;
  88. {
  89.     prt_request->iodrp.io_Command = PRD_DUMPRPORT;
  90.     prt_request->iodrp.io_RastPort = &screen->RastPort;
  91.     prt_request->iodrp.io_ColorMap = screen->ViewPort.ColorMap;
  92.     prt_request->iodrp.io_Modes = screen->ViewPort.Modes;
  93.     prt_request->iodrp.io_SrcX = 0;
  94.     prt_request->iodrp.io_SrcY = 0;
  95.     prt_request->iodrp.io_SrcWidth = screen->Width;
  96.     prt_request->iodrp.io_SrcHeight = screen->Height;
  97.     prt_request->iodrp.io_DestCols = screen->Width;
  98.     prt_request->iodrp.io_DestRows = screen->Height;
  99.     prt_request->iodrp.io_Special = 0;
  100.     return ( DoIO ( prt_request ) );
  101. }
  102.